<?php
include('../config.php');
$username = $_GET['username'];
$password = $_GET['password'];
$sql = "select * from users where name='$username' and password='$password'";
//资源类型(php从mysql里取到的原始数据)
$res = mysql_query($sql);
// 获取res的长度
// $rows = mysql_num_rows($res);
// echo "<meta charset = 'utf-8'>";
// if($rows > 0){
//     echo "登录成功，<a href='../html/sy.html'>回到首页</a>";
// }else{
//     echo "登录失败，<a href ='../html/login.html'>请重新登录</a>";
// }
$list = array();
// 通过循环去资源里抓取数据，每取一行，都是一个$row，取完了循环也就结束了
while ($row = mysql_fetch_assoc($res)) {
  array_push($list, $row);
}
// echo "username";
if ($list) {
    echo json_encode(array(
      "code" => 200,
      "body" => array(
        "msg" => '登录成功'
      )
    ));
  } else {
    echo json_encode(array(
      "code" => 201,
      "body" => array(
        "msg" => '登录失败，请重试'
      )
    ));
  }
?>